<html>
    <head>
        <title>Login to The Bret</title>
        <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
        <link type="text/css" rel="stylesheet" href="CSS/Desktop/login.css"/>
        <script src="js/Desktop/jquery-2.1.0.min.js"></script>
        <script src="js/Desktop/md5.js"></script>
        <script src="js/Desktop/soapclient.js"></script>
        <script>
            var curRequests = [];
            function validate(){
                if(document.login.username.value !== "" && document.login.password.value !== ""){
                    document.getElementById('error').style.display = 'none';
                    $.post('/bret/ws/login', {
                        'email': document.login.username.value.trim(),
                        'password': hex_md5(document.login.password.value.trim()),
                    }).done(function(data) {
                        var r = JSON.parse(data);
                        if (r === null) {
                            document.getElementById('error').textContent = 'Email and password does not match. Please try again';
                            document.getElementById('error').style.display = 'inherit';
                        } else if (r.email !== "") {
                            if (r.password === '28651b0d8fb8d3153a83c569658c79ee') {
                                window.location.href = '<?php echo $GLOBALS['host']; ?>/home';
                            }
                            else
                                window.location.reload(true);
                        }
                    });
                } else {
                    document.getElementById('error').textContent = 'You can not leave with empty username or password';
                    document.getElementById('error').style.display = 'inherit';
                }
            }
        </script>
    </head>
    <body>
        <div class="wrapper">
            <div class="buzzpulse-header-bar centered">
                <div class="header content clearfix"><img alt="buzzpulse" class="logo"
                src="Images/Bret_Logo.png"></div>
            </div>
            <div class="main content clearfix">
                <div class="card signin-card">
                    <p class="profile-name"></p>
                    <form name="login" action="" method="POST" onsubmit="validate(); return false;">
                        <label class="label">Username</label>
                        <input id="id_username" name="username" type="text">
                        <label class="label">Password</label>
                        <input id="id_password" name="password" type="password">
                        <div id="error" style="color: #fff; margin-bottom: 5px; display: none">&nbsp;</div>
                        <input class="rc-button rc-button-submit" type="submit" value="Log in">
                        <input type="checkbox" class="css-checkbox" id="checkbox" checked="checked">
                        <label class="label remember">Remember Me</label>
                    </form>
                </div>
                <div class="get-info">
                    <a class="forgot-password-link" href="#">Register</a><span>|</span>
                    <a class="forgot-password-link" href="#">Lost your password?</a>
                </div>
            </div>
        </div>
    </body>
</html>

